<?php 

include './function.php';

	if($_POST){

		$page = !empty($_POST['page']) ? $_POST['page'] : 1;

		$list_num = !empty($_POST['list']) ? $_POST['list'] :'';

		$page_size = 4;

		$p = page($page, $page_size, './Face/');//点击页码，每页循环个数，文件路径

		$offset = $p[0];		

		$path = $p[1];

		$arr = array();

		$class = uniqid();

		foreach ($path as $value) {

			$b =  date("Y-m-d H:i:s",filemtime($value));

	        $filesize = filesize($value);

			$value = iconv("gb2312","UTF-8", $value);
				
			$pp = strrchr($value, '/');
			
			$str = "<tr class=\"$class\"><td> <img src=$value alt=''></td><td> \"$pp\"</td><td> $b</td><td> $filesize</td><td><a href=\"./down.php?name= $value \" class=\"glyphicon glyphicon-download-alt\" aria-hidden=\"true\"></a></td><td><a href=\"./del.php?name= $value\" class=\"glyphicon glyphicon-trash\" aria-hidden=\"true\"></a></td></tr>";

			array_push($arr, $str);

		}

		if($page > $offset-$list_num){	
		//当页面超过最大页面数与页面选择列表的一半的差时，获得这个差值作为当前页面；		
			$page = $offset-$list_num;
		}

		if($page < $list_num+1){
		//当页面小于页面选择列表的一半的值时，获得这个值作为当前页面；	
			$page = $list_num+1;
		}

		$page_menu = array();

		$list = array();

		
		for ($i=$page-$list_num;$i <= $page+$list_num;$i++) {  //循环显示出页面
		
	   		$page_list = "<li id=\"li\" class=\"li\"><a>$i</a></li>";

	   		array_push($page_menu, $page_list);
	  	
		}
		
		array_push($arr, $class);

		$list[0] = $page_menu;

		array_push($arr, $list);

		echo json_encode($arr);
			
	}













 ?>